<link type="text/css" href="/admins/js/jquery/css/ui-lightness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="/admins/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/js/boxy/js/jquery.boxy.js"></script>
<link href="/js/boxy/css/boxy.css" media="screen" rel="stylesheet" type="text/css" >  
<script type="text/javascript">
    $(function(){
        window.alert = Boxy.alert;
        window.confirm = Boxy.confirm;
    });
</script>
<div class="admin_nrtop">
    <div class="ad_search">
        <form action=""  method="get" style="margin:0px" id="form1">
            <div class="search">
                <div class="soubox">
                    <input type="text" id="quick" name="quick" value="<?php echo $this->quick ? $this->quick : ""; ?>" placeholder="输入仓库号/用户名等"/>
                    <input type="hidden" id="timescope" name="timescope" value="<?php echo $this->timescope ? $this->timescope : ""; ?>" />
                    <input type="hidden" id="starttime" name="starttime" value="<?php echo $this->starttime ? $this->starttime : ""; ?>"/>
                    <input type="hidden" id="endtime" name="endtime" value="<?php echo $this->endtime ? $this->endtime : ""; ?>" />
                    <input type="hidden" id="pagesize" name="pagesize" value="<?php echo $this->pagesize ? $this->pagesize : 10; ?>" />
                    <input type="hidden" id="objectType" name="objectType" value="<?php echo $this->objectType === "" ? "" : $this->objectType; ?>" />
                    <input type="hidden" id="moneyMax" name="moneyMax" value="<?php echo $this->moneyMax === "" ? "" : $this->moneyMax; ?>" />
                    <input type="hidden" id="moneyMin" name="moneyMin" value="<?php echo $this->moneyMin === "" ? "" : $this->moneyMin; ?>" />
                    <input type="hidden" id="moneyType" name="moneyType" value="<?php echo $this->moneyType === "" ? "" : $this->moneyType; ?>" />
                    <input type="hidden" id="statusid" name="statusid" value="<?php echo $this->statusid === "" ? "" : $this->statusid; ?>" />
                    <a href="javascript:$('#form1').submit();"><span>搜索</span></a>
                </div>
            </div>

            <div class="timebox">
                <div class="ad_time">
                    <div class="timezdy">
                        <div class="timeselect2">
                            <span><?php
                                if ($this->timescope) {
                                    switch ($this->timescope) {
                                        case "week":
                                            echo "本周";
                                            break;
                                        case "lastweek":
                                            echo "上周";
                                            break;
                                        case "month":
                                            echo "本月";
                                            break;
                                        case "lastmonth":
                                            echo "上月";
                                            break;
                                        case "quarter":
                                            echo "本季";
                                            break;
                                        case "lastquarter":
                                            echo "上季";
                                            break;
                                        case "year":
                                            echo "今年";
                                            break;
                                        case "lastyear":
                                            echo "去年";
                                            break;
                                        case "day7":
                                            echo "近7天";
                                            break;
                                        case "day30":
                                            echo "近30天";
                                            break;
                                        default:
                                            echo "范围选择";
                                            break;
                                    }
                                } else {
                                    echo "范围选择";
                                }
                                ?>
                            </span><i></i>
                        </div>
                        <div class="timeslelct_xl" style="display:none;">
                            <ul>
                                <li><a href="javascript:setstart('week')">本周</a></li>
                                <li><a href="javascript:setstart('lastweek')">上周</a></li>
                                <li><a href="javascript:setstart('month')">本月</a></li>
                                <li><a href="javascript:setstart('lastmonth')">上月</a></li>
                                <li><a href="javascript:setstart('quarter')">本季</a></li>
                                <li><a href="javascript:setstart('lastquarter')">上季</a></li>
                                <li><a href="javascript:setstart('year')">今年</a></li>
                                <li><a href="javascript:setstart('lastyear')">去年</a></li>
                                <li><a href="javascript:setstart('day7')">近7天</a></li>
                                <li><a href="javascript:setstart('day30')">近30天</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="timefw">
                        <div class="time">
                            <div class="timeselect"  id="stime">
                                <span id="stimeval"><?php echo $this->starttime ? $this->starttime : date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 90, date("Y"))); ?></span><i></i>
                            </div>
                            <div class="timeslelctbox">
                            </div>
                        </div>
                        <div class="timezhi">
                            <span>至</span>
                        </div>
                        <div class="time" >
                            <div class="timeselect" id="etime">
                                <span id="etimeval"><?php echo $this->endtime ? $this->endtime : date("Y-m-d"); ?></span><i></i>
                            </div>
                            <div class="timeslelctbox">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="timeok">
                    <a href="javascript:$('#form1').submit();">确定</a>
                </div>
            </div>
            <div class="xianshi">
                <label>显示：</label>
                <ul>
                    <li <?php echo $this->pagesize ? ($this->pagesize == 10 ? 'class="xson"' : "") : 'class="xson"'; ?>><a href="javascript:void(0)" class="setpagesize" name="10">10</a></li>
                    <li <?php echo $this->pagesize ? ($this->pagesize == 20 ? 'class="xson"' : "") : ""; ?>><a href="javascript:void(0)" class="setpagesize" name="20">20</a></li>
                    <li <?php echo $this->pagesize ? ($this->pagesize == 30 ? 'class="xson"' : "") : ""; ?>><a href="javascript:void(0)" class="setpagesize" name="30">30</a></li>
                </ul>
            </div>
        </form>
    </div>
</div>
<div  class="biaoge">
    <div class="biaotbody">
        <table>
            <tr>
                <th class="li7">
                    <div class="lileft">创建时间</div>
                </th>
                <th class="li3">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>类型</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php  foreach ($this->ObjectTypeAll as $objectTypeVal) { ?>
                                    <li><a href="javascript:void(0)" class="setObject" name="<?php echo $objectTypeVal->id;?>"><?php echo $objectTypeVal->name; ?></a></li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li3">
                    <div class="lileft">关联信息</div>
                </th>
                <th class="li15" >
                    <div class="lileft">原因</div>
                </th>
                <th class="li5">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>金额</span>
                            <i></i>
                        </div>
                        <div class="biaofw" style="display:none;">
                            <input type="text"  id="minMoney" name="minMoney" onkeyup="value = value.replace(/[^\d]/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
                            <span>至</span>
                            <input type="text"  id="maxMoney" name="maxMoney" onkeyup="value = value.replace(/[^\d]/g, '')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
                            <a href="javascript:void(0)" class="setMoney">确定</a>
                        </div>
                    </div>
                </th>
                <th class="li9">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>金额类型</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php  foreach ($this->MoneyTypeAll as $key => $moneyTypeVal) { ?>
                                    <li><a href="javascript:void(0)" class="setMoneyType" name="<?php echo $key;?>"><?php echo $moneyTypeVal; ?></a></li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li5" >
                    <div class="lileft">申请人</div>
                </th>
                <th class="li7"><div class="lileft">用户信息</div></th>
                <th class="li5">
                    <div class="biaoxiala">
                        <div class="lixiala">
                            <span>状态</span>
                            <i></i>
                        </div>
                        <div class="biaoxllb" style="display:none;">
                            <ul>
                                <?php if ($this->StatusAll) {
                                    foreach ($this->StatusAll as $key => $statusVal) { ?>
                                    <li><a href="javascript:void(0)" class="setStatus" name="<?php echo $key; ?>"><?php echo $statusVal; ?></a></li>
                                <?php } } ?>
                            </ul>
                        </div>
                    </div>
                </th>
                <th class="li505"><div class="lijz">操作</div></th>
            </tr>
        </table>
    </div>
    <?php if (($this->objectType && $this->objectItem) || $this->moneyMax || $this->moneyMin || $this->moneyType || ($this->statusid !== "" && $this->statusid !== null)) { ?>
        <div class="xzinfo">
            <ul>
            <?php if ($this->objectType && $this->objectItem) { ?><li><div class="xzinfobox"><span><?php echo $this->objectItem->Name;?></span><a href="javascript:void(0)" title="撤销" class="removeset" name="objectType"><i>撤销</i></a></div></li><?php } ?>
            <?php if ($this->moneyMax || $this->moneyMin) { ?><li><div class="xzinfobox">
                    <span>金额：
                        <?php echo ($this->moneyMax && $this->moneyMin)?"￥".$this->moneyMin." 至 ￥".$this->moneyMax:($this->moneyMax?"小于￥".$this->moneyMax:"大于￥".$this->moneyMin); ?>
                    </span>
                    <a href="javascript:void(0" title="撤销" class="removeset" name="money"><i>撤销</i></a></div></li><?php } ?>
            <?php if ($this->moneyType) { ?><li><div class="xzinfobox"><span><?php echo $this->MoneyTypeAll["$this->moneyType"]; ?></span><a href="javascript:void(0)" title="撤销" class="removeset" name="moneyType"><i>撤销</i></a></div></li><?php } ?>
            <?php if ($this->statusid === "" && $this->statusid !== null) {  } else { ?><li><div class="xzinfobox"><span><?php echo $this->StatusAll["$this->statusid"]; ?></span><a href="javascript:void(0)" title="撤销" class="removeset" name="statusid"><i>撤销</i></a></div></li><?php } ?>
            </ul>
        </div>
    <?php } ?>
    <div class="table" style="margin-top: 0px;">
        <table>
            <style>.tr_4{color: #c00;font-size: 14px;}</style>
            <?php if ($this->financialList) {
                foreach ($this->financialList as $key => $Item) { ?>
            <tr style="height: 50px;" class="tr_<?php echo $Item->ObjectType;?>">
                    <td class="li7"><div class="lileft"><?php echo $Item->DateCreated;?></div></td>
                    <td class="li3"><div class="lileft"><?php echo $Item->ObjectItem->Name;?></div></td>
                    <td class="li3"><div class="lileft"><a href="/admini/<?php echo $Item->ObjectRelevance.$Item->ObjectId;?>" target="_blank" class="indexa"><?php echo $Item->ObjectId;?></a></div></td>
                    <td class="li15"><div class="lileft"><?php echo $Item->Reason;?></div></td>
                    <td class="li5"><div class="lileft"><?php echo $Item->Money;?></div></td>
                    <td class="li9"><div class="lileft"><?php echo $Item->MoneyTypeName;?></div></td>
                    <td class="li5"><div class="lileft"><?php echo $Item->applyName;?></div></td>
                    <td class="li7"><div class="lileft"><a href="/admini/manageuser/userdetail/id/<?php echo $Item->UserId;?>" target="_blank" class="indexa"><?php echo $Item->User->Storeno."(".$Item->User->Nikename.")";?></a></div></td>
                    <td class="li5"><div class="lileft"><?php echo $Item->StatusName;?></div></td>
                    <td class="li505"><div class="lijz">
                        <div class="lixlnav" style="width: 80px;">
                            <?php switch ($Item->Status) {
                                 case Application_Model_FinancialCheckItem::Status_Auto:
                                     echo "已完成";
                                     break; 
                                 case Application_Model_FinancialCheckItem::Status_Pending:
                            ?>
                            <a class="xlnavxq pending" href="javascript:void(0)" name="<?php echo $Item->Id;?>">审核</a>
                            <div class="xlnavlistbox" >
                                <a class="xlnavsj" href="javascript:void(0)"><i></i></a>
                                <div class="xlnavlist" style="display:none;">
                                    <ul>
                                        <li><a href="javascript:void(0)" name="<?php echo $Item->id;?>" class="reject">驳回</a></li>
                                    </ul>
                                </div>
                            </div>
                            <?php break;
                                 case Application_Model_FinancialCheckItem::Status_Trial: ?>
                                <a class="xlnavxq close" href="javascript:void(0)" name="<?php echo $Item->Id;?>">关闭</a>
                            <?php break;
                                 case Application_Model_FinancialCheckItem::Status_Reject: ?>
                                <a class="xlnavxq rejectClose" href="javascript:void(0)" name="<?php echo $Item->Id;?>">驳回关闭</a>
                            <?php   break;
                                 case Application_Model_FinancialCheckItem::Status_Close:
                                    echo "关闭";
                                    break;
                                 case Application_Model_FinancialCheckItem::status_RejectClose:
                                     echo "驳回关闭";
                                     break;
                                 default:
                                     echo "未知状态";
                                     break;
                             }?>
                         </div>
                    </div></td>
                </tr>
            <?php }
                } else {
                    echo '<div class="tablebox">暂时无数据</div>';
                } ?>
        </table>
    </div>
</div>
<div class="toolbar">
<?php
echo $this->partial('paging.phtml', array("pages" => $this->financialAll, "pamas" => "quick=$this->quick&timescope=$this->timescope&starttime=$this->starttime&endtime=$this->endtime&pagesize=$this->pagesize&objectType=$this->objectType&moneyMax=$this->moneyMax&moneyMin=$this->moneyMin&moneyType=$this->moneyType&statusid=$this->statusid"));
?>
</div>   
<script>
    $(function(){
        $('.soubox label').click(function() {
            $(this).parent().find('input').focus();
        });
        $(".timezdy").click(function() {
            $(".timezdy .timeselect2").attr("class", "timeselect2 timeon");
            $(".timeslelct_xl").attr("style", "display:block;");
        });
        $(".timezdy").mouseleave(function() {
            $(".timeselect2").attr("class", "timeselect2");
            $(".timeslelct_xl").attr("style", "display:none;");
        });
        $("#stime").click(function() {
            $(this).attr("class", "timeselect t_on");
            WdatePicker({el: 'stimeval', vel: 'starttime', onpicked: function() {
                    $("#stime,#etime").attr("class", "timeselect");
                    $(".soubox #timescope").val("");
                }});
        });
        $("#etime").click(function() {
            $(this).attr("class", "timeselect t_on");
            WdatePicker({el: 'etimeval', vel: 'endtime', onpicked: function() {
                    $("#stime,#etime").attr("class", "timeselect");
                    $(".soubox #timescope").val("");
                }});
        });

        $(".lixiala").click(function() {
            $(".lixiala").attr("class", "lixiala");
            $(".lixiala").next("div").attr("style", "display:none;");

            $(this).attr("class", "lixiala bton");
            $(this).next("div").attr("style", "display:block;");
        });
        $(document).bind("click", function(e) {
            var target = $(e.target);
            if (target.closest(".biaoxiala").length == 0) {
                $(".lixiala").attr("class", "lixiala");
                $(".lixiala").next("div").attr("style", "display:none;");
            }
            if (target.closest("#stime").length == 0) {
                $("#stime").attr("class", "timeselect");
            }
            if (target.closest("#etime").length == 0) {
                $("#etime").attr("class", "timeselect");
            }
        });
        $('.countryzm a').each(function(index, item) {
            $(item).click(function() {
                $('.countryzm li.zmon').removeClass('zmon');
                $(this).parent().addClass('zmon');
                $('#countryTab ul').hide();
                $('#countryTab ul').eq(index).show();
                return false;
            });
        });
        $('.countrylist a').bind('click', function() {
            $(".soubox #cityid").val($(this).attr('cid'));
            $('#form1').submit();
        });

        $(".xlnavsj").live("mousemove", function() {
            $(this).next("div").attr("style", "display:block;");
        });
        $(".lixlnav").mouseleave(function() {
            $(".xlnavsj").next("div").attr("style", "display:none;");
        });
        $(".setpagesize").click(function(){
            var name = $(this).attr("name");
            $("#form1 #pagesize").val(name);
            $("#form1").submit();
        });
        $(".setObject").click(function(){
            var name = $(this).attr("name");
            $("#form1 #objectType").val(name);
            $("#form1").submit();
        });
        $(".setMoney").click(function(){
            var minMoney = $("#minMoney") .val();
            var maxMoney = $("#maxMoney") .val();
            if(maxMoney == "" && minMoney == ""){
                alert("起始金额和结束金额不能一起不空！");
                return ;
            } else if(maxMoney != "" && minMoney != "") {
                if(maxMoney < minMoney){
                    alert("起始金额不能大于结束金额！");
                    return ;
                }
            }
            $("#form1 #moneyMax").val(maxMoney);
            $("#form1 #moneyMin").val(minMoney);
            $("#form1").submit();
        });
        $(".setMoneyType").click(function(){
            var name = $(this).attr("name");
            $("#form1 #moneyType").val(name);
            $("#form1").submit();
        });
        $(".setStatus").click(function(){
            var name = $(this).attr("name");
            $("#form1 #statusid").val(name);
            $("#form1").submit();
        });
        $(".removeset").click(function(){
            var name = $(this).attr("name");
            if(name == "money"){
                $("#form1 #moneyMax").val("");
                $("#form1 #moneyMin").val("");
                $("#form1").submit();
            }
            $("#form1 #"+name).val("");
            $("#form1").submit();
        });
        
        $(".pending").click(function(){
            var name = $(this).attr("name");
            confirm("您确认该单您已经审核无差错吗？",function(){
                $.post("/admini/financial/pending",{"id":name},function(data){
                    if(data == 1){
                        alert("审核成功！");
                        location.reload();
                    } else if (data == 2){
                        alert("状态错误，不能审核！");
                    } else if (data == 9){
                        alert("您没有权限审核该记录！");
                    } else {
                        alert("出现未知错误！");
                    }
                });
            });
        });
        $(".close").click(function(){
            var name = $(this).attr("name");
            $.post("/admini/financial/close",{"id":name},function(data){
                if(data == 1){
                    alert("关闭成功！");
                    location.reload();
                } else if (data == 2){
                        alert("状态错误，不能关闭！");
                } else if (data == 9){
                    alert("您没有权限关闭该记录！");
                } else {
                    alert("出现未知错误！");
                }
            });
        });
        $(".reject").click(function(){
            var name = $(this).attr("name");
            confirm("您确认该单错误，需要驳回处理？",function(){
                $.post("/admini/financial/reject",{"id":name},function(data){
                    if(data == 1){
                        alert("驳回成功！");
                        location.reload();
                    } else if (data == 2){
                        alert("状态错误，不能驳回！");
                    } else if (data == 9){
                        alert("您没有权限驳回该记录！");
                    } else {
                        alert("出现未知错误！");
                    }
                });
            });
        });
        $(".rejectClose").click(function(){
            var name = $(this).attr("name");
            $.post("/admini/financial/rejectclose",{"id":name},function(data){
                if(data == 1){
                    alert("关闭驳回成功！");
                    location.reload();
                } else if (data == 2){
                        alert("状态错误，不能关闭驳回！");
                } else if (data == 9){
                    alert("您没有权限关闭该记录的驳回！");
                } else {
                    alert("出现未知错误！");
                }
            });
        });
    });
</script>
